<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>用户登录页面</title>
<head>
</head>
<body>
<%-- <%	
		request.setCharacterEncoding("utf-8");
		String uid=request.getParameter("uid");
		String password=request.getParameter("password");
		
	 	Connection conn=null;
		Statement stat=null;
		ResultSet rs=null;
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		String url="jdbc:mysql://127.0.0.1:3306/alumniRecord";
		String user="root";
		String passwords="wangyang";
		conn=DriverManager.getConnection(url,user,passwords);
		stat=conn.createStatement();
		 
		String sql="select * from user where uid='"+uid+"' and password ='"+password+"';";
		rs=stat.executeQuery(sql);
		//out.println("登录成功!");
		
		  while (rs.next()) {
		    out.println(rs.getString("uid"));
		    out.println(rs.getString("password"));
		} 
		 /* while(rs.next()) {
		    if(password.equals(rs.getString("password"))){
		    	out.println("成功");
		    }else{
		    	out.println("失败");
		    }
		  }  */ 
		
		  /* if(rs.next()) {
		    if(password.equals(rs.getString("password"))){
		    	session.setAttribute("uid",uid);
		    	response.sendRedirect("index.jsp");
		    	
		    }
		    else{
		    	String errorType="1";
		    	//out.println("dengLu.jsp");
		    	response.sendRedirect("404.jsp?errorType="+errorType);
		    }
		   
		   
		} 
		 else{
			 String errorType="2";
				response.sendRedirect("404.jsp?errorType="+errorType);	
	    }   */
  
	%>  
	
	 --%>
		
<jsp:useBean id="db" class="com.DBManager" scope="session"></jsp:useBean>
	<jsp:useBean id="adminUser" class="com.UserInfo" scope="session"></jsp:useBean>
	<%	
	ResultSet rs=null;
	try{
		request.setCharacterEncoding("utf-8");
		String uid=request.getParameter("uid");
		String password=request.getParameter("password");
		request.getSession().setAttribute("uid",uid);//将用户名保存在整个会话期间  
		String sql="select * from user where uid='"+uid+"' and password ='"+password+"';";
		rs = db.getResult(sql);
		//out.println(uid+password);
		if(rs.next()){
			if(password.equals(rs.getString("password")))
				adminUser.setUid(uid);
				adminUser.setPassword(password);
				session.setAttribute("adminUser", adminUser);
				out.print("登录成功!");
				out.print("欢迎您:"+uid);
				response.setHeader("refresh", "1;url=index-stu.jsp");
		}else{
			out.println("用户名或者是密码错误，3秒后为您跳转到登录页面");
			response.setHeader("refresh", "3;url=login.jsp");
		}
	}catch(NumberFormatException e){
		e.printStackTrace();
	}
	rs.close();
	db.Release();
	%> 
	
</body>
</html>